package com.seeyoui.kensite.framework.cms.article.service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.seeyoui.kensite.common.base.service.BaseService;
import com.seeyoui.kensite.framework.cms.article.domain.ArticleVO;
import com.seeyoui.kensite.framework.cms.article.persistence.ArticleQueryMapper;
@Service
public class ArticleQueryService extends BaseService  {
	
	@Autowired
	private ArticleQueryMapper articleQueryMapper;
	
	/**
	 * 根据栏目id查询文章列表
	 * @param categoryId
	 * @return
	 */
	public List<ArticleVO> listArticleByCategoryId(String categoryId) {
		List<ArticleVO> articleList = articleQueryMapper
				.listArticleByCategoryId(categoryId);
		return articleList;
	}
	
	/**
	 * 根据栏目id查询三会一课文章
	 * @param categoryId
	 * @return
	 */
	public List<ArticleVO> listArticleActivityByCategoryId(String categoryId) {
		List<ArticleVO> articleList = articleQueryMapper
				.listArticleActivityByCategoryId(categoryId);
		return articleList;
	}
	
	/**
	 * 根据模块id查询文章列表
	 * @param portletId
	 * @return
	 */
	public List<ArticleVO> listArticleByPortletId(ArticleVO articleVO) {
		List<ArticleVO> articleList = articleQueryMapper
				.listArticleByPortletId(articleVO);
		return articleList;
	}
	
	/**
	 * 查询三会一课党员活动会议纪要
	 * @param type
	 * @return
	 */
	public List<ArticleVO> listSummary(Integer type) {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("type", type);
		List<ArticleVO> articleList = articleQueryMapper.listSummary(map);
		return articleList;
	}
	
	/**
	 * 根据id查询文章
	 * 返回VO对象，app接口传输
	 * @param id
	 * @return ArticleVO
	 */
	public ArticleVO findArticleDetailById(String id) {
		ArticleVO article = articleQueryMapper.findArticleDetailById(id);
		List<String> posterList = new ArrayList<String>();
		posterList.add(article.getPoster());
		article.setPosterList(posterList);
		return article;
	}
	
	/**
	 * 根据pageIndex查询两学一做栏目下各模块的文章
	 * app端专用
	 * @param pageIndex
	 * @return
	 */
	public List<ArticleVO> listArticleByPortletIdApp(int pageIndex) {
		List<ArticleVO> articleList = new ArrayList<ArticleVO>();
		if (pageIndex == 0) {
			String portletId = "49fb37b470c84e239a81ba1a068a3174";
			articleList = articleQueryMapper.listArticleByPortletIdMob(portletId);
		} else if (pageIndex == 1) {
			String portletId = "d92cde910d864e6e9e71758714500d6f";
			articleList = articleQueryMapper.listArticleByPortletIdMob(portletId);
		} else if (pageIndex == 2) {
			String portletId = "c1a95ba1ff3746d48f806275a4d79d3b";
			articleList = articleQueryMapper.listArticleByPortletIdMob(portletId);
		} else if (pageIndex == 3) {
			String portletId = "3239ce34111b47a88dd549b0d66534e1";
			articleList = articleQueryMapper.listArticleByPortletIdMob(portletId);
		}
		return articleList;
	}
	
	/**
	 * 根据用户ID查询最近获得积分的文章列表，取前10条记录
	 * @param userId
	 * @return
	 */
	public List<ArticleVO> findArticleForPoint(String userId) {
		return articleQueryMapper.findArticleForPoint(userId);
	}
}
